package com.zzuli.admin.controller;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.zzuli.admin.common.ResultSuccess;
import com.zzuli.admin.entity.User;
import com.zzuli.admin.sersvice.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.util.Map;

@Api(tags = "用户数据接口")
@RestController
@CrossOrigin
public class UserController {

    @Resource
    UserService userService;

   @ApiOperation(value = "查询用户")
   @GetMapping("/user")
   public String queryUser(@RequestParam("page") int page,@RequestParam("limit") int limit,
                           @RequestParam("nickName") String nickName,@RequestParam("email") String email){
       Map<String, Object> map = userService.quryUser(page, limit,nickName,email);
       String s = JSON.toJSONString(map);
       return s;
   }

    @ApiOperation(value = "添加用户")
    @PostMapping("/addUser")
    public String addUser(@RequestBody  User user){
        String s = userService.addUser(user);
        return s;
    }

    @ApiOperation(value = "删除")
    @GetMapping("/deleteUser")
    public String removeUser(@RequestParam Long id){
        String s = userService.removeUser(id);
        return s;
    }

    @ApiOperation(value = "更新")
    @PostMapping("/updateUser")
    public String updateUser(@RequestBody User user){
        String s = userService.updateUser(user);
        return s;
    }
}
